package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.dto.PageDto;
import com.qf.mapper.DtsGrouponMapper;
import com.qf.pojo.DtsGroupon;
import com.qf.service.DtsGrouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @author 邢式瑞
 * @version 1.0
 * @project E-commercebackGroundManagementSystem
 * @date 2022/9/25 15:16
 */
@Service
public class DtsGrouponServiceImpl implements DtsGrouponService {
    @Autowired
    private DtsGrouponMapper dtsGrouponMapper;
    @Override
    public Page<DtsGroupon> selectPage(PageDto pageDto) {
        Page<DtsGroupon> dtsGrouponPage = new Page<>(pageDto.getPage(), pageDto.getLimit());
        QueryWrapper<DtsGroupon> dtsGrouponQueryWrapper = new QueryWrapper<>();
        //page: 1
//limit: 20
//rulesId: sss
//sort: add_time
//order: desc  admin/groupon/listRecord
        dtsGrouponQueryWrapper.eq(pageDto.getRulesId()!=null,"rules_id",pageDto.getRulesId()).orderBy(!StringUtils.isEmpty(pageDto.getSort()), "asc".equalsIgnoreCase(pageDto.getOrder()), pageDto.getSort());
        return dtsGrouponMapper.selectPage(dtsGrouponPage,dtsGrouponQueryWrapper);
    }
}
